package com.evola.dbsm.view.login
{
	import com.evola.dbsm.communication.Commands;
	import com.evola.dbsm.model.UserBean;
	import com.evola.dbsm.service.RemoteServiceFacade;
	import com.evola.dbsm.service.ServiceResult;

	import mx.core.Application;
	import mx.managers.PopUpManager;

	[Bindable]
	public class LoginPresenter
	{

		public var view:LoginView;
		public var model:LoginModel=new LoginModel();

		public function LoginPresenter()
		{

		}

		public function init():void
		{

			model.init();
		}

		public function login():void
		{

			RemoteServiceFacade.executeCommand(Commands.LOGIN_COMMAND, {username: model.username, password: model.password}, onLoginSuccess);
		}

		private function onLoginSuccess(result:ServiceResult):void
		{

			var user:UserBean=result.data as UserBean;

			if (user)
			{

				PopUpManager.removePopUp(view);

				Presenters.mainPresenter.login(result.data as UserBean);
			}
		}

	}
}
